package com.jiwei.system.interceptor;


import cn.yiban.open.Authorize;
import cn.yiban.open.FrameUtil;
import com.jiwei.system.serviceImpl.MemberServiceImpl;
import com.jiwei.system.vo.Login;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class UserLoginInterceptor implements HandlerInterceptor {
    @Resource(name = "MemberService")
    private MemberServiceImpl memberService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String phoneNumber = (String) request.getSession().getAttribute("userlogin");

        if(request.getServletPath().equals("/repair/login")){
            if (request.getMethod().equals("POST"))
                return true;
            else if(phoneNumber != null){
                System.out.println(1);
                response.sendRedirect("index");
                return true;
            }
            else
                return true;
        }
        else if( phoneNumber == null){
            response.sendRedirect("login");
            return false;
        }
        else{
            return true;
        }
//return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
